package com.jinlia.show.common.core.utils;

public class StringUtils {

    public static String decimalTo60(int num) {
        /*
         * 将10进制数转换为60进制数
         */
        int base = 60;
        String digits = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz";
        StringBuilder result = new StringBuilder();
        while (num > 0) {
            int remainder = num % base;
            result.insert(0, digits.charAt(remainder));
            num = num / base;
        }
        return result.toString();
    }
    public static int base60ToDecimal(String num) {
        /*
         * 将60进制数转换为10进制数
         */
        int base = 60;
        int result = 0;
        for (int i = 0; i < num.length(); i++) {
            int digit = num.charAt(i);
            if (digit >= '0' && digit <= '9') {
                digit -= '0';
            } else if (digit >= 'A' && digit <= 'Z') {
                digit = digit - 'A' + 10;
            } else if (digit >= 'a' && digit <= 'z') {
                digit = digit - 'a' + 36;
            } else if (digit == '_') {
                digit = 62;
            } else if (digit == '-') {
                digit = 63;
            } else {
                throw new IllegalArgumentException("Invalid character in input");
            }
            result = result * base + digit;
        }
        return result;
    }


    public static void main(String[] args) {
        String s = decimalTo60(132);
        System.out.println(s);
        int i = base60ToDecimal("I");
        System.out.println(i);
    }
}
